<?php
declare (strict_types=1);

namespace app\common\model;

class ProductCate extends Base
{

    public static function getAll()
    {
        try {

            $result = parent::where('is_del', 0)->order('sort', 'asc')->select()->toArray();
            return mergeMenu($result);

        } catch (\Exception $e) {
            return [];
        }
    }

    public static function getCate($id = 0, $business_id=0)
    {
        $cate = parent::where(['pid' => $id, 'is_del' => 0, 'status' => 1]);
        if($business_id){
            if($cateIds = Business::where('id', $business_id)->value('cate_1')){
                $cate->whereIn('id', $cateIds);
            }else{
                $cate->where(false);
            }

        }
        $cate = $cate->field("id,icon,title,'cate' as type")->order('sort')->select();

        return $cate;
    }

    public static function getBusinessCate($id = 0, $cate_1 = '')
    {
        $that = parent::where(['pid' => $id, 'is_del' => 0, 'status' => 1]);
        if (!$id && $cate_1) {
            $that->whereIn('id', $cate_1);
        }
        return $that->field('id,title')->select();

    }


}
